package actions;

import jason.asSemantics.DefaultInternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Atom;
import jason.asSyntax.Term;

import java.util.Random;

public class random_direction extends DefaultInternalAction{

	@Override
	public Object execute(TransitionSystem ts, Unifier un, Term[] args)
			throws Exception {
		
		/*Term x = args[0];
		Term y = args[1];
		Term newX = args[2];
		Term newY = args[3];*/
		Term direction = args[0];
		String direcao = "";
		
		// Unfold terms
		/*double vx = ((NumberTerm)x).solve();
		double vy = ((NumberTerm)y).solve();
		*/
		
		Random r = new Random();
		int nextInt = r.nextInt(8);
		Direction direc = Direction.NORTH;
		switch(nextInt){
		case 0:
			direc = Direction.NORTH;
			break;
		case 1:
			direc = Direction.SOUTH;
			break;
		case 2:
			direc = Direction.WEST;
			break;
		case 3:
			direc = Direction.EAST;
			break;
		case 4:
			direc = Direction.NORTHEAST;
			break;
		case 5:
			direc = Direction.NORTHWEST;
			break;
		case 6:
			direc = Direction.SOUTHEAST;
			break;
		case 7:
			direc = Direction.SOUTHWEST;
			break;
		}
		/*double vNewX = r.nextBoolean() ? (vx + nextInt) : (vx - nextInt);
		nextInt = r.nextInt(2);
		double vNewY = r.nextBoolean() ? (vy + nextInt) : (vy - nextInt);
		// Update output terms
		un.unifies(newX, new NumberTermImpl(vNewX));
		un.unifies(newY, new NumberTermImpl(vNewY));*/
		// everything ok, so returns true
		Thread.sleep(50);
		un.unifies(direction, new Atom(direc.getValue()));
		return true;
	}

}
